<template>
  <div class="login_container">
    <div class="login_box">
      <div class="title_box">
        <img
          src="@/assets/logo/light.svg"
          alt=""
          width="64px"
          style="margin-right: 12px"
        />
        <span class="title-text">CDAPP-TREX</span>
      </div>
      <el-form label-width="0px" class="login_in">
        <el-form-item prop="username">
          <el-input
            v-model="username"
            type="text"
            placeholder="请输入姓名、新工号或老工号"
            prefix-icon="el-icon-user"
            @keyup.enter.native="$refs['password'].focus()"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            ref="password"
            v-model="password"
            type="password"
            placeholder="请输入密码（区分大小写）"
            prefix-icon="el-icon-key"
            @keyup.enter.native="login"
          ></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="login">登录</el-button>
          <!-- <el-button @click="reset">重置</el-button> -->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "loginView",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    login() {
      this.$store
        .dispatch("login", {
          string: this.username,
          passwd: this.password,
        })
        .then((status) => {
          if (status === 0) {
            this.$router.push("/");
          } else {
            this.$notify.error("登录失败");
          }
        });
    },
    reset() {},
  },
};
</script>

<style scoped>
.login_container {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 101;
  /* background-color: #42b983; */
  background-color: #909399;
}

.login_box {
  width: calc(100vw - 20px);
  max-width: 450px;
  height: calc(100vh - 100px);
  max-height: 300px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.title_box {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px 0;
  font-size: 24px;
  color: #909399;
}

.title-text {
  font-size: 30px;
  color: #909399;
}

.avatar_box {
  height: 130px;
  width: 130px;
  /* border: 1px solid #eee; */
  border-radius: 50%;
  /* box-shadow: 0 0 10px #ddd; */
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #fff;
  padding: 10px;
}

.avatar_box img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #eee;
}

.btns {
  display: flex;
  justify-content: flex-end;
}

.login_in {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
</style>
